package com.example.ffepeg.ffeAdder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ffedelete {

    public static void main(String[] args) {
        // 视频输入输出路径及水印位置信息   去除水印
        String inputVideoPath = "https://cdn1.suno.ai/fa421931-b29e-4a57-b409-4d14a5a6cbad.mp4";
        int startX = 310; // X坐标
        int startY = 700;  // Y坐标
        int watermarkWidth = 190;  // 宽度
        int watermarkHeight = 50; // 高度
        String outputVideoPath = "D:\\javaXM\\FFEpeg\\src\\main\\resources\\out\\video.mp4";

        // 构建FFmpeg命令
        String[] command = {
                "ffmpeg",
                "-i", inputVideoPath,
                "-vf", "delogo=x=" + startX + ":y=" + startY + ":w=" + watermarkWidth + ":h=" + watermarkHeight, "-c:v", "libx264",
                "-preset", "veryslow",
                "-crf", "16",
                "-b:v", "8000k",
                "-c:a", "copy",
                outputVideoPath
        };

        // 使用ProcessBuilder执行命令
        ProcessBuilder processBuilder = new ProcessBuilder(command);
        processBuilder.redirectErrorStream(true); // 将错误流合并到标准输出流
        try {
            // 启动进程
            Process process = processBuilder.start();
            // 读取FFmpeg的输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            // 等待进程完成
            int exitCode = process.waitFor();
            System.out.println("FFmpeg 进程退出码: " + exitCode);

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

}
